package com.banksoft.admin.controller;

import com.banksoft.admin.dao.ParamsDao;
import com.banksoft.admin.entity.Params;
import com.banksoft.admin.service.BaseService;
import com.banksoft.common.BaseController;
import com.banksoft.common.ConfigHelper;
import com.banksoft.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2016/5/6.
 */
@Controller
@RequestMapping("/params")
public class ParamsController extends BaseController {

    @Autowired
    BaseService baseService;

    @RequestMapping("/view")
    public String view(Model model){
        ConfigHelper instance = ConfigHelper.GetInstance();
        model.addAttribute("GoldFee",instance.GetConfig("Gold_Fee"));
        model.addAttribute("GeneralFee",instance.GetConfig("General_Fee"));
        model.addAttribute("PartnerFee",instance.GetConfig("Partner_Fee"));
        model.addAttribute("GoldAmount",instance.GetConfig("Gold_Amount"));
        model.addAttribute("GeneralAmount",instance.GetConfig("General_Amount"));
        model.addAttribute("PartnerAmount",instance.GetConfig("Partner_Amount"));
        model.addAttribute("CustomerZjcd",instance.GetConfig("Customer_Zjcd"));
        model.addAttribute("MemberZjcd",instance.GetConfig("Member_Zjcd"));
        model.addAttribute("ManageFee",instance.GetConfig("ManageFee"));
        model.addAttribute("TxMinAmount",instance.GetConfig("TxMinAmount"));
        model.addAttribute("TransferAmout",instance.GetConfig("TransferAmout"));
        model.addAttribute("TxFee",instance.GetConfig("TxFee"));
        model.addAttribute("RetailFee",instance.GetConfig("RetailFee"));
        model.addAttribute("AutoFh",instance.GetConfig("AutoFh"));
        return "params/params_view";
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(String GoldFee,String GeneralFee,String PartnerFee,String GoldAmount, String GeneralAmount, String PartnerAmount,
                       String CustomerZjcd,String MemberZjcd, String ManageFee,String TxMinAmount,String TransferAmout,String TxFee,String RetailFee,
                       String AutoFh,HttpServletRequest request){
        try {
            ConfigHelper instance = ConfigHelper.GetInstance();
            instance.SetConfig("Gold_Fee",GoldFee);
            instance.SetConfig("General_Fee",GeneralFee);
            instance.SetConfig("Partner_Fee",PartnerFee);
            instance.SetConfig("Gold_Amount",GoldAmount);
            instance.SetConfig("General_Amount",GeneralAmount);
            instance.SetConfig("Partner_Amount",PartnerAmount);
            instance.SetConfig("Customer_Zjcd",CustomerZjcd);
            instance.SetConfig("Member_Zjcd",MemberZjcd);
            instance.SetConfig("ManageFee",ManageFee);
            instance.SetConfig("TxMinAmount",TxMinAmount);
            instance.SetConfig("TransferAmout",TransferAmout);
            instance.SetConfig("TxFee",TxFee);
            instance.SetConfig("RetailFee",RetailFee);
            instance.SetConfig("AutoFh",AutoFh);

            this.saveLog("修改奖励参数设置",request);
            return this.FmtResult(true,"保存成功",null);
        }catch (Exception e){
            e.printStackTrace();
            return this.FmtResult(false,"保存失败"+e.getMessage(),null);
        }
    }

    @RequestMapping("/wxView")
    public String wxView(Model model){
        ConfigHelper instance = ConfigHelper.GetInstance();
        model.addAttribute("shareTitle",instance.GetConfig("ShareTitle"));
        model.addAttribute("shareDesc",instance.GetConfig("ShareDesc"));
        model.addAttribute("shareImg",instance.GetConfig("ShareImg"));

        return "params/params_wx";
    }

    @RequestMapping("/wxSave")
    @ResponseBody
    public Object wxSave(String shareTitle,String shareDesc,String shareImg,HttpServletRequest request){
        try {
            ConfigHelper instance = ConfigHelper.GetInstance();
            instance.SetConfig("ShareTitle",shareTitle);
            instance.SetConfig("ShareDesc",shareDesc);
            instance.SetConfig("ShareImg",shareImg);

            this.saveLog("修改微信分享设置",request);
            return this.FmtResult(true,"保存成功",null);
        }catch (Exception e){
            e.printStackTrace();
            return this.FmtResult(false,"保存失败"+e.getMessage(),null);
        }
    }


}
